<?php
require_once("../config.php"); 
require_once("../model/DB.php");
require_once("../model/User.php");
require_once("../model/Class.php");

$class = Classes::getClassById($_POST['Class']);

if($class['teacher_id']){
	if($class['teacher_id']!=$_POST['id']){
		echo "class";
		return false;
	}
}

if($_POST['id']!=0){
  if($_POST['Class']=="auto"){
	$auto = Classes::autoTeacher($grade);
	if($auto){
		if(User::edit($_POST['id'],$_POST['name'],$_POST['password'],$_POST['realname'],$_POST['contact'])){
			
			Classes::removeTeacher($_POST['id']);
			Classes::editTeacher($auto['id'],$_POST['id']);
			echo "saved";		
				

		}	
				
	}
	else{
		echo "allclass";
	}	
	
  }else{
		if(User::edit($_POST['id'],$_POST['name'],$_POST['password'],$_POST['realname'],$_POST['contact'])){
			
			Classes::removeTeacher($_POST['id']);
			Classes::editTeacher($_POST['Class'],$_POST['id']);
			echo "saved";		
				

		}  
  }  
}
else{
  if($_POST['Class']=="auto"){
	$auto = Classes::autoTeacher($grade);
	
	if($auto){
		if(User::edit($_POST['id'],$_POST['name'],$_POST['password'],$_POST['realname'],$_POST['contact'])){
			
			Classes::editTeacher($auto['id'],$last['id']);
			$last = User::getLastId();
			echo "added";	
				

		}	
				
	}
	else{
		echo "allclass";
	}	
	
  }
  else{
	if(User::add($_POST['name'],$_POST['password'],$_POST['realname'],$_POST['contact'],'teacher')){
		$last = User::getLastId();
		Classes::editTeacher($_POST['Class'],$last['id']);
		echo "added";
	}
  }
	
	
}


?>